import React from 'react'

function LazyRouter(componentfn) {
    class LazyloadComponent extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                component: null
            }
        }
        async componentDidMount() { //注意参考文档中使用的componentWillMount将被废除
            const { default: component } = await componentfn();
            this.setState({ component })
        }
        render() {
            const C = this.state.component;
            return C ? <C {...this.props} /> : null;
        }
    }
    return LazyloadComponent
}
export default LazyRouter